﻿using MediatR;
using T.Materials.Domain.Model;
using T.Materials.Read.API.ApplicationRead.Command.MaterialRequisitionCommand;
using T.Materials.Repository.MaterialsInterface;

namespace T.Materials.Read.API.ApplicationRead.CommandHandler.MaterialRequisitionCommandHandler
{
    /// <summary>
    /// 物资领用反填命令处理器
    /// </summary>
    public class ReverseMaterialRequisitionCommandHandler : IRequestHandler<ReverseMaterialRequisitionCommand, MaterialRequisition>
    {
        /// <summary>
        /// 物资领用仓储接口
        /// </summary>
        protected readonly IMaterialRequisitionRepository materialRequisitionRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="materialRequisitionRepository">物资领用仓储接口</param>
        public ReverseMaterialRequisitionCommandHandler(IMaterialRequisitionRepository materialRequisitionRepository)
        {
            this.materialRequisitionRepository = materialRequisitionRepository;
        }

        /// <summary>
        /// 处理反填物资领用命令
        /// </summary>
        /// <param name="request">反填物资领用命令</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回物资领用实体</returns>
        public async Task<MaterialRequisition> Handle(ReverseMaterialRequisitionCommand request, CancellationToken cancellationToken)
        {
            return await materialRequisitionRepository.GetModelAsync(request.MaterialRequisitionId);
        }
    }
}
